package com.laikan.reader.bookshelf.adapter.holder;

import android.net.Uri;
import android.view.View;
import android.widget.TextView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.laikan.reader.core.base.BaseHolder;
import com.laikan.reader.core.LaikanApplication;
import com.laikan.reader.R;
import com.laikan.reader.core.bean.FreeBookBean;

/**
 * 书架免费福利item
 * Created by Administrator on 2016/3/24.
 */
public class FreeBooksHolder extends BaseHolder<FreeBookBean> {

    private SimpleDraweeView book_img;
    private TextView book_name;
    private TextView book_writer;
    private TextView book_des;

    @Override
    public View initView() {
        view = View.inflate(LaikanApplication.applicationContext, R.layout.lk_book_cate_item, null);
        book_img = (SimpleDraweeView)view.findViewById(R.id.book_img);
        book_name = (TextView)view.findViewById(R.id.book_name);
        book_writer = (TextView)view.findViewById(R.id.book_writer);
        book_des = (TextView)view.findViewById(R.id.book_des);
        return view;
    }

    @Override
    public void refreshView() {
        FreeBookBean b = getData();
        if (b != null) {
            // 1.书的封面
            book_img.setImageURI(Uri.parse(b.getIcon()));

            // 2.书名
            book_name.setText(b.getName());

            // 3.作者名
            book_writer.setText("作者： " + b.getAuthorName());

            // 4.简介
            book_des.setText(b.getIntroduce());

            // 5.设置书籍右上角标签 背景色
            setTagColor(book_img, b.getChannel());
        }
    }

    private void setTagColor(SimpleDraweeView book_img, int channel) {
        book_img.setMaxWidth(15);
        switch (channel) {
            case 1:
            case 2:
                book_img.setTag("限免");
                book_img.setBackgroundColor(LaikanApplication.applicationContext.getResources().getColor(R.color.C_3399FF));
                break;
            case 3:
                book_img.setTag("特价");
                book_img.setBackgroundColor(LaikanApplication.applicationContext.getResources().getColor(R.color.C_EE0022));
                break;
        }
    }
}
